#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

const int kMaxN = (int)1e6;
const int kMaxAi = (int)1e6;
const int kMaxSqrtPri = (int)2e6;

vector<int> pri_list;
bool not_pri[kMaxSqrtPri + 1] = {false};
int a[kMaxN];
long long sum_ai[kMaxAi + 1];
int cnt_ai[kMaxAi + 1];
vector<long long> ans_list;
vector<pair<long long, int>> factors;

void GenPriList(){
    for(int x = 2; x < kMaxSqrtPri; x++){
        if(!not_pri[x]){
            pri_list.push_back(x);
            cerr << x << endl;
        }
        for(int pri : pri_list){
            if(pri * x >= kMaxSqrtPri){
                break;
            }
            not_pri[pri * x] = true;
            if(x % pri == 0){
                break;
            }
        }
    }
} 

void GenFactors(long long s){
    for(int pri : pri_list){
        int cnt = 0;
        
        for(; s % pri == 0; s /= pri){
            cnt++;
        }
        if(cnt){
            factors.push_back(make_pair((long long)pri, cnt));
        }
        if(s < pri){
            break;
        }
    }
    if(s != 1){
        factors.push_back(make_pair(s, 1));
    }
}

void GenAnsList(long long max_ans, long long ans, int dep){
    if(ans > max_ans){
        return;
    }
    if(dep == factors.size()){
        ans_list.push_back(ans);
        return;
    }
    for(int i = 0; i <= factors[dep].second; i++){
        GenAnsList(max_ans, ans, dep + 1);
        ans *= factors[dep].first;
    } 
}

bool IsAns(long long x, long long k, int n, int max_ai){
    if(x >= max_ai){
        k -= x * n - sum_ai[max_ai];
    }
    else{
        long long xx = x;
        
        for( ; xx <= max_ai; xx += x){
            k -= xx * (cnt_ai[xx] - cnt_ai[xx - x]) - (sum_ai[xx] - sum_ai[xx - x]);
        }
        k -= xx * (cnt_ai[max_ai] - cnt_ai[xx - x]) - (sum_ai[max_ai] - sum_ai[xx - x]);
    }
    return k >= 0;
}

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    int T;
    
    GenPriList();
    for(cin >> T; T; T--){
        int n, max_ai = 0;
        long long k, s;
        
        cin >> n >> k;
        for(int i = 0; i < n; i++){
            cin >> a[i];
            max_ai = max(max_ai, a[i]);
        }
        
        //calc sum_ai & cnt_ai
        fill(cnt_ai, cnt_ai + max_ai + 1, 0);
        fill(sum_ai, sum_ai + max_ai + 1, 0);
        for(int i = 0; i < n; i++){
            sum_ai[a[i]] += a[i];
            cnt_ai[a[i]]++; 
        }
        for(int i = 1; i <= max_ai; i++){
            sum_ai[i] += sum_ai[i - 1];
            cnt_ai[i] += cnt_ai[i - 1];
        }
        
        //GenFactors
        s = sum_ai[max_ai] + k;
        factors.clear(); 
        GenFactors(s); 
        
        //GenAnsList
        ans_list.clear();
        GenAnsList(s / n, 1, 0);
        sort(ans_list.begin(), ans_list.end());
        
        //GetAns
        for(int i = ans_list.size() - 1; i >= 0; i--){
            if(IsAns(ans_list[i], k, n, max_ai)){
                cout << ans_list[i] << endl;
                break;
            }
        }
    }
    return 0;
} 
